﻿Imports System.IO
Public Class frmKilometrosOperativos
    Dim Bitacora As New clsActividad
    Dim Usuario As New clsUsuarioPrincipal
    Private Sub frmKilometrosOperativos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ToolStrip1.Cursor = Cursors.Hand
        ToolStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System
        frmMain.statusActividad.Text = ": Módulo de Pagobus"

        Bitacora.RegistraActividad("Ingresó al Módulo de Pagobus")
        Usuario.Ubicacion("Módulo de Pagobus")

        txtFile.Clear()
        txtFile.Focus()

    End Sub

    Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
        Dim xl As Object
        Dim wb As Object

        'Crear objeto excel
        xl = CreateObject("Excel.Application")
        xl.Visible = False
        wb = xl.activeworkbook
        wb = xl.Workbooks.Open(txtFile.Text)

        Dim rng As Integer = 2
        Dim col As Integer = 2
        Dim i As Integer = 5
        Dim cont As Integer = 0

        Dim Autobus As String = ""
        Dim Kilometros As Double = 0
        Dim Kms As New clsKilometrosOperativos

        For i = 2 To 10000
            Autobus = wb.sheets(1).cells(i, 2).value
            If Autobus = "" Then
                Exit For
            End If
            Kilometros = wb.sheets(1).cells(i, 15).value
            Kms.Vehiculo = Autobus
            Kms.Fecha = datFecha.Value
            Kms.Kilometros = Kilometros
            Kms.Insertar()

        Next

        'cerramos el archivo Excel
        wb.CLOSE(False)
        xl.quit()
        xl = Nothing

        txtFile.Clear()
        MsgBox("Kilometros Importados", MsgBoxStyle.Information, "Aviso")

    End Sub

    Private Sub btnBuscarLiquidador_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscarLiquidador.Click
        Dim oFD As New OpenFileDialog
        With oFD
            .Title = "Seleccionar fichero"
            .Filter = "Ficheros de texto (*.xls;*.xlsx)|*.xls;*.xlsx" & _
                      "|Todos los ficheros (*.*)|*.*"
            .FileName = Me.txtFile.Text
            If .ShowDialog = System.Windows.Forms.DialogResult.OK Then
                Me.txtFile.Text = .FileName
            End If
        End With
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Close()

    End Sub
End Class